package org.jadestudio.home.action;

import java.util.List;
import java.util.Map;
import java.util.Properties;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.jadestudio.home.service.ArticleService;
import org.jadestudio.home.service.FeedService;
import org.jadestudio.home.service.LeaderboardService;
//import org.jadestudio.dsdown.util.SysInfo;

// 首页管理
public class IndexAction extends Action {
	private ArticleService articleService;
	private LeaderboardService leaderboardService;
	private FeedService feedService;
	private Map<String,Long> memUsed;
	private Properties sysinfo;
	
	public ArticleService getArticleService() {
		return articleService;
	}
	public void setArticleService(ArticleService articleService) {
		this.articleService = articleService;
	}
	
	public LeaderboardService getLeaderboardService() {
		return leaderboardService;
	}
	public void setLeaderboardService(LeaderboardService leaderboardService) {
		this.leaderboardService = leaderboardService;
	}
	
	public FeedService getFeedService() {
		return feedService;
	}
	public void setFeedService(FeedService feedService) {
		this.feedService = feedService;
	}
	
	public IndexAction(){
		
	}
	/**
	 * 加载数据
	 */
	@SuppressWarnings("unchecked")
	public ActionForward execute(ActionMapping mapping, ActionForm form,
            HttpServletRequest request,
            HttpServletResponse response) throws Exception{
		
		// 加载首页文章榜
		List<java.util.Map> articleList = articleService.getHomePageArticleList();
		request.setAttribute("articleList", articleList);
		
		// 加载橱窗列表
		List<java.util.Map> feedList = feedService.getFeedList();
		request.setAttribute("feedList", feedList);
		
		// 加载排行榜
		java.util.Map count = leaderboardService.getGameArticleCount();
		List<java.util.Map> gameTop10 = leaderboardService.getGameTop10();  //热门游戏
		List<java.util.Map> gameRecentTop10 = leaderboardService.getRecentGameTop10();  //最近发售
		List<java.util.Map> articleTop10 = leaderboardService.getArticleTop10();
		
		request.setAttribute("count", count);
		request.setAttribute("gameTop10", gameTop10);
		request.setAttribute("gameRecentTop10", gameRecentTop10);
		request.setAttribute("articleTop10", articleTop10);
		return mapping.findForward("success");
		
	}
}